const {contentModel} = require("../mongdb");
const {success,fail} = require("../toast") 
module.exports=function test(router){ 
        // 查
    router.get("/content",async ctx=>{ //路由方式及地址
       try {
           const data =await contentModel.find({});
           return success(ctx,data)
       } catch (error) {
           return fail(ctx,error)
       }
    } )
    // 增加
    router.post("/content",async ctx=>{ 
       try {
           const data =await contentModel.create(ctx.request.body)
           return success(ctx,data)
       } catch (error) {
        return fail(ctx,error)
       }
    } )
    //删除
    router.delete("/content",async ctx=>{ 
       try {
           const data =await contentModel.deleteOne(ctx.request.body)
           return success(ctx,data)
       } catch (error) {
        return fail(ctx,error)
       }
    } )
//修改
router.put("/content",async ctx=>{
    try { //方法封装过后
        const data = await  contentModel.updateOne(ctx.query,ctx.request.body);
        return success(ctx,data);
    } catch (error) {
        return fail(ctx,error);  
    }
    })

//结束
}